package com.xbongbong.config;

import com.xbongbong.parent.abstracts.AbstractSpecialDataAnalysisHelp;
import com.xbongbong.parent.interfaces.StageExecuteHandle;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 吴峰
 * @date 2021/11/22 19:31
 */
@Component
public class StageExecuteConfig implements ApplicationContextAware {

    private Map<String, StageExecuteHandle> stageExecuteMap;

    @Bean("stageExecuteMap")
    public Map<Integer, StageExecuteHandle> initStageExecute() {
        return stageExecuteMap.values().stream().collect(Collectors.toMap(StageExecuteHandle::type, t -> t));
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        stageExecuteMap = applicationContext.getBeansOfType(StageExecuteHandle.class);
    }
}
